<template>
  <div>
     <div class="head">
        {{msg}}
    </div>
    <scroller :on-infinite="infinite"
      :on-refresh="refresh"
               :refreshText="refreshText" ref="my_scroller" style="padding-top:1rem;">
      <div ></div>
      <div v-for="(item, index) in items" :key="index"
          class="row" :class="{'grey-bg': index % 2 == 0}">
        {{ item }}
      </div>
    </scroller>
  </div>
</template>
<script>

export default {
  components: {

  },

  data() {
    return {
     page:0,
      msg: "文章列表页",
      refreshText:'拉你妹啊',
      noDataText:'没了没了',
      items:[],
      showMore : true
    };
  },

  mounted() {
    this.getData(this.page)
    this.top = 1;
    this.bottom = 20;
  },

  methods: {
    async getData(page){
      try {
       var res =  await this.axios.post('/api/queryArticles',{
          page:this.page,
          count:10,
          all:true
        })
        if(res.data.data.length > 0){
          for(var i=0;i<res.data.data.length;i++){
            this.items.push(res.data.data[i])
          }
        }else{
          this.showMore = false
        }
        console.log(res.data.data)
      } catch (error) {

      }
    },
    refresh(done) {
      setTimeout(() => {
        //写下拉刷新逻辑
        console.log("下拉刷新");
        done();
      }, 1500);
    },
    infinite(done) {
      if (!this.showMore) {
        setTimeout(() => {
          done(true);
        }, 1500);
        return;
      }
      setTimeout(() => {
        this.page++
        this.getData()
        setTimeout(() => {
          done();
        });
      }, 1500);
    }
  }
};
</script>
<style lang="scss" scoped>
.head{
  width: 100%;
  height: 1rem;
  line-height: 1rem;
  text-align: center;
  background: #fff;
  box-shadow: 2px 2px 2px #ddd;
  position: relative;
  z-index: 999;
  font-size: 0.35rem;
}
.row{
  background: #ddd;
  border-bottom: 1px solid #fff;
  height: 1.5rem;
}
</style>
